import 'package:flutter/material.dart';

// void main() {
//   runApp(const MyApp());
// }
//
// class MyApp extends StatelessWidget {
//   const MyApp({super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     return MaterialApp(
//       title: 'AnimatedAlign Demo',
//       home: const AnimatedAlignPage(),
//     );
//   }
// }

class AnimatedAlignPage extends StatefulWidget {
  const AnimatedAlignPage({super.key});

  @override
  State<AnimatedAlignPage> createState() => _AnimatedAlignPageState();
}

class _AnimatedAlignPageState extends State<AnimatedAlignPage> {
  bool _isTopLeft = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('AnimatedAlign 学习案例')),
      body: Container(
        color: Colors.grey.shade200,
        width: double.infinity,
        height: double.infinity,
        child: AnimatedAlign(
          duration: const Duration(seconds: 1), // 动画时长
          curve: Curves.easeInOut,              // 缓入缓出效果
          alignment: _isTopLeft ? Alignment.topLeft : Alignment.bottomRight,
          child: Container(
            width: 80,
            height: 80,
            decoration: const BoxDecoration(
              color: Colors.blue,
              shape: BoxShape.circle,
            ),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _isTopLeft = !_isTopLeft; // 切换状态触发对齐动画
          });
        },
        child: const Icon(Icons.swap_horiz),
      ),
    );
  }
}
